package okw.gui;

import okw.database.DatabaseManager;
import okw.database.Election;
import okw.database.Voter;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class SelectVoter {
	
	public SelectVoter(Shell parent, final String id){
		final Shell shell  = new Shell(parent, SWT.TITLE|SWT.SYSTEM_MODAL| SWT.CLOSE | SWT.MAX);
		
		Label label = new Label(shell, SWT.CENTER);
		label.setText("Czy odznaczyc tego wyborce?");
		label.setLocation(20,20);
		label.pack();
		
		Button button = new Button(shell, SWT.PUSH);
		button.setText("Tak");
		button.setLocation(60,40);
		button.pack();
		
		Button button2 = new Button(shell, SWT.PUSH);
		button2.setText("Nie");
		button2.setLocation(100,40);
		button2.pack();
		
		button.addSelectionListener(new SelectionListener() {
			
			public void widgetSelected(SelectionEvent arg0) {
				DatabaseManager db = DatabaseManager.getInstance();
				Voter voter = db.getVoter(id);
				voter.setHasVoted(true);
				db.update(voter);
				MainWindowO.aktualizujGlosujacych();
				shell.close();
			}
			
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
		});
		
		button2.addSelectionListener(new SelectionListener() {
			
			public void widgetSelected(SelectionEvent arg0) {
				shell.close();
				
				
			}
			
			public void widgetDefaultSelected(SelectionEvent arg0) {	
			}
		});
		
		shell.pack(); 
		MainWindowO.center(shell);
		shell.open();
	}

}
